package com.littlec.sdk.entity;

import java.util.ArrayList;
import java.util.List;

public class CMGroup {
	private String groupId;
	private String groupName;
	private List<CMMember> memberList;
	private boolean isMute;
	private String groupDesc;
	private boolean isPublic = false;
	private String chairMan = null;
	private int maxNumbers = 100;

	public CMGroup() {
	}

	public CMGroup(String id, String name) {
		this.groupId = id;
		this.groupName = name;
	}

	public CMGroup(String id, String name, boolean isMute) {
		this.groupId = id;
		this.groupName = name;
		this.isMute = isMute;
	}

	public String getGroupId() {
		return this.groupId;
	}

	public void setGroupId(String groupId) {
		this.groupId = groupId;
	}

	public String getGroupName() {
		return this.groupName;
	}

	public void setGroupName(String groupName) {
		this.groupName = groupName;
	}

	public boolean isMute() {
		return this.isMute;
	}

	public void setMute(boolean isMute) {
		this.isMute = isMute;
	}

	public String getGroupDesc() {
		return this.groupDesc;
	}

	public void setGroupDesc(String groupDesc) {
		this.groupDesc = groupDesc;
	}

	public int getMaxNumbers() {
		return this.maxNumbers;
	}

	public void setMaxNumbers(int maxNumbers) {
		this.maxNumbers = maxNumbers;
	}

	public boolean isPublic() {
		return this.isPublic;
	}

	public void setPublic(boolean isPublic) {
		this.isPublic = isPublic;
	}

	public List<CMMember> getMembers() {
		return this.memberList;
	}

	public void setMembers(List<CMMember> members) {
		this.memberList = members;
	}

	public String getMembersString(String separation) {
		if ((this.memberList == null) || (this.memberList.size() <= 0)) {
			return "";
		}
		StringBuilder builder = new StringBuilder();
		for (CMMember member : this.memberList) {
			if (member.getMemberId().equals("default_user_1")) {
				builder.append("СС");
			} else if (member.getMemberId().equals("default_user_2")) {
				builder.append("ϪϪ");
			} else {
				builder.append(member.getMemberNick());
			}
			builder.append(separation);
		}
		builder.deleteCharAt(builder.length() - 1);
		return builder.toString();
	}

	public int getMembersCount() {
		if (this.memberList == null)
			return 0;
		return this.memberList.size();
	}

	public void addMember(CMMember cmMember) {
		if (this.memberList == null) {
			this.memberList = new ArrayList();
		}
		this.memberList.add(cmMember);
	}

	public void addMembers(List<CMMember> members) {
		if ((members == null) || (members.size() < 1)) {
			return;
		}
		for (CMMember member : members)
			addMember(member);
	}

	public void removeMember(CMMember member) {
		if (this.memberList != null)
			this.memberList.remove(member);
	}

	public int hashCode() {
		int prime = 31;
		int result = 1;
		result = 31 * result
				+ (this.groupId == null ? 0 : this.groupId.hashCode());
		return result;
	}

	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		CMGroup other = (CMGroup) obj;
		if (this.groupId == null) {
			if (other.groupId != null)
				return false;
		} else if (!this.groupId.equals(other.groupId))
			return false;
		return true;
	}
}
